package com.twu.biblioteca.util;

import com.twu.biblioteca.model.Library;

public class CheckOutMenu implements IMenuEntry {

    private static final String THANK_YOU_MESSAGE = "Thank you! Enjoy the %s";
    private static final String ERROR_MESSAGE = "That %s is not available. (It is either checked out or spelling error in %s name)";

    public static String getThankYouMessage() {
        return THANK_YOU_MESSAGE;
    }

    public static String getErrorMessage() {
        return ERROR_MESSAGE;
    }

    @Override
    public String handle(String args) {
        Library library = LibraryService.getInstance().getLibrary();
        String username = "xxx-xxxx";
        String[] partsOfArgs = args.split(" ",2);
        if(library.checkOut(partsOfArgs[1],partsOfArgs[0],username)) {
            return String.format(getThankYouMessage(),partsOfArgs[0]);
        } else
            return String.format(getErrorMessage(),partsOfArgs[0],partsOfArgs[0]);

    }
}
